<!doctype html>

<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<?php
include_once('navbar.php');
include_once('superheader.php');
?>

<script type="text/javascript">
$(document).ready( function () {
	
	$( "#subset" ).buttonset();
    $( "#datepicker" ).datepicker();
    $( "#datepicker2" ).datepicker();
    $( "#button5" ).button();
    $( "#button6" ).button();
    $( "#button9" ).button();
    $("#response").html("");

          var params =  {
          colReq2: "software",
        };

        var data = JSON.stringify(params);

        $.ajax({
                    cache: false,
                    type: "json",
                    url: "/phpfunctions/lists/listSoftware.php",
                    contentType: "application/json",
                    processData: true,
                    data: data,
                    success: function(res, textStatus, jqXHR){
		      var container = $("#response");
			 var table = $("<table border=\"1\">");
			 var head = $("<tr>");
			 //head.append("<th>MongoId</th>");
			 head.append("<th>Name</th>");
			 head.append("<th>Barcode</th>");
			 head.append("<th>Type</th>");
			 head.append("<th>Commission Date</th>");
			 head.append("<th>Decomission Date</th>");
			 head.append("<th>Description</th>");
		 	 table.append(head);

			 for(var key in res.data.messages)
			 {
				var tr = $("<tr>");
				var message = res.data.messages[key];
				var td = $("<td>");
				/*td.html(message['_id']);
				tr.append(td);*/
					
				var td = $("<td>");
				td.html(message.name);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.barcode);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.type);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.comDate);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.decomDate);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.description);
				tr.append(td);
					
				table.append(tr);			
			 }
                         //container.append(JSON.stringify(res['data']));
			container.html(table);
                    },
                    complete: function(XMLHttpRequest, text_status) {

                    }
                  });
    
    
    
    
    
    
    
    
});
</script>

</head>


<body>
	<div id="response" style="position: relative; top:10px; left:400px; height:0px">
      Stuff to be replaced
    </div>
	<h2>Add Software:</h2>
	<?php if(isset($_GET["error"])) : ?>
<?php if($_GET["error"] == 'emptySoft') : ?>
    <div class="ui-widget">
	<p>Please enter all fields have valid information.</p>
	</div>
	<?php endif; ?>
	<?php if($_GET["error"] == 'duplicateSoft') : ?>
    <div class="ui-widget">
	<p>Software with that barcode already exists.</p>
	</div>
	<?php endif; ?>
	<?php if($_GET["error"] == 'dateSoft') : ?>
    <div class="ui-widget">
	<p>Ensure decomission date entered is prior to commission date.</p>
	</div>
	<?php endif; ?>
<?php endif; ?>
	<form action="phpfunctions/addsoftware.php" method="post">
 	<p>Name: <input type="text" name="name"><br><p>
 	<p>Barcode: <input type="text" name="barcode"><p>
 	<p>Commission Date: <input type="text" name="comDate" id="datepicker" /></p>
 	<p>Decommission Date: <input type="text" name="decomDate" id="datepicker2" /></p>
 	<p>Description: <input type="text" name="description" /></p>
 	<input type="radio" name="type" value="Application">Application Software<br>
 	<input type="radio" name="type" value="System">System Software<br>
 	<input type="radio" name="type" value="Computer Programming Tool">Computer Programming Tool<br>
 	<input type="radio" name="type" value="other">Other<br>
 	<button id="button5" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
	
	<?php if($_SESSION['role'] != "user") : ?>
	<h2>Remove Software:</h2>
	<?php if(isset($_GET["error"])) : ?>
		<?php if($_GET["error"] == 'deleteErrorSoftware') : ?>
    	<div class="ui-widget">
		<p>No software with that barcode was found.</p>
		</div>
		<?php endif; ?>
	<?php endif; ?>
	<form action="phpfunctions/deletesoftware.php" method="post">
 	<p>Barcode: <input type="text" name="barcode"><br><p>
 	<button id="button6" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
	<?php endif; ?>
	
	<h2>Filter By Type:</h2>
	<form action="softwarefiltertype.php" method="post">
 	<p>Type: <input type="text" name="type"><br><p>
 	<button id="button9" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>

</body>